<template>
    <div class="school">
        <h2>学校名称:{{ name }}</h2>
        <h2>学校名称:{{ address }}</h2>
        <button @click="sendSchoolName">把学校给父组件</button>
    </div>
</template>

<script>
import pubsub from "pubsub-js"

export default {
    name: "School",
    props: ["getSchoolName"],
    data() {
        return {
            name: "冯镠霖School",
            address: "中国School",
            pubId : 0
        }
    },
    mounted() {
      let pubId =pubsub.subscribe("hello", (messageName, data) => {
        console.log(a,b)
        console.log("我订阅了消息，等待别人发送给我")
      })
    },
    methods: {
        sendSchoolName() {
            console.log(this.getSchoolName)
            this.getSchoolName(this.name)
        }
    },
  beforeDestroy() {
      pubsub.unsubscribe(this.pubId)
  }
}
</script>

<style scoped>
.school {
    background-color: #e59625;
}
</style>